#!/usr/bin/env python
from django.core.management import execute_manager
import shutil
import compileall
import re
import os

def grem(path, pattern):
    for each in os.listdir(path):
        if pattern.match(each):
	    name = os.path.join(path, each)
	    try: os.remove(name)
	    except:
		grem(name, pattern)
		os.rmdir(name)

compileall.compile_dir (".")
for root, dirs, files in os.walk('compilado', topdown=False):
    for name in files:
        os.remove(os.path.join(root, name))
    for name in dirs:
        os.rmdir(os.path.join(root, name))
os.rmdir("compilado")

shutil.copytree (".", "compilado")
for i in ['(?P<name>\w+).py~$', '(?P<name>\w+).py$']:
    regex = re.compile(i)
    grem ('compilado/monedas', regex)
    grem ('compilado/sistema', regex)
    grem ('compilado/productos', regex)
    grem ('compilado/contactos', regex)
    grem ('compilado/ventas', regex)
    grem ('compilado/modules', regex)
